<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
			<el-form-item label="用户名">
				<el-input v-model="form.username"></el-input>
			</el-form-item>
			<el-form-item label="性别">
				<el-radio-group v-model="form.sex">
					<el-radio label="1"> 男</el-radio>
					<el-radio label="2">女</el-radio>
					<el-radio label="3">保密</el-radio>
				</el-radio-group>
			</el-form-item>
			<el-form-item label="城市">
				<el-select v-model="form.cityName" placeholder="请选择城市">
					<el-option label="北京" value="shanghai"></el-option>
					<el-option label="上海" value="beijing"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item label="密码">
				<el-input v-model="form.password" show-password></el-input>
			</el-form-item>

			<el-form-item>
				<el-button type="primary" @click="reg()">注册</el-button>
				<el-button>取消</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import axios from "axios"
	export default {
		data() {
			return {
				form: {
					username: '',
					sex: '',
					cityName: '',
					password: ''
				}
			}
		},
		methods: {
			onSubmit() {
				console.log('submit!');
			},
			reg() {
				axios.post('http://localhost:8072/api/user/register', this.form).then(res => {
					console.log(res.data);
					if (res.data.code == 1) {
						this.$message({
							message: '恭喜你，注册成功',
							type: 'success'
						});
						
						this.$router.push({
							path:'/login'
						})
						
					} else {
						this.$message.error('注册失败');
					}
				})
			}
		}
	}
</script>

<style>
</style>